package com.weixing.mall.provider.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.weixing.mall.provider.mapper.BrandMapper;
import com.weixing.mall.provider.mapper.CategoryBrandMapper;
import com.weixing.mall.provider.model.domain.Brand;
import com.weixing.mall.provider.model.domain.CategoryBrand;
import com.weixing.mall.provider.model.dto.BrandDto;
import com.weixing.mall.provider.model.query.BrandQuery;
import com.weixing.mall.provider.model.vo.BrandVo;
import com.weixing.mall.provider.service.IBrandService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @ClassName BrandServiceImpl
 * @Description TODO <br/>
 * @Author gjq
 * @Modified By:
 * @Date 2019/8/6
 * @Version 1.0
 **/
/**
 * <p>
 * 商品模块-商品品牌表 服务实现类
 * </p>
 *
 * @author Small
 * @since 2019-11-20
 */
@Service
public class BrandServiceImpl extends ServiceImpl<BrandMapper, Brand> implements IBrandService {
    @Autowired
    private CategoryBrandMapper categoryBrandMapper;

    @Override
    public void save(BrandDto brandDto) {
        Brand brand = new Brand();
        BeanUtils.copyProperties(brandDto,brand);
        brand.setIsEnable(brandDto.getIsEnable().getValue());
        if (null == brandDto.getId()){
            save(brand);
        }else{
            updateById(brand);
        }
    }

    @Override
    public IPage<BrandVo> selectOfPage(Page page, BrandQuery brandQuery) {
        return baseMapper.selectListOfPage(page,brandQuery);
    }

    @Override
    public int deleteAll(int[] ids) {
        return baseMapper.delAll(ids);
    }

    @Override
    public CategoryBrand selectBrand(Integer brandId) {
        return categoryBrandMapper.selectBrand(brandId);
    }
}
